/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.ruchin.tek.employees.json;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
import ru.ruchin.tek.employees.data.Employee;

/**
 *
 * @author yruchin
 */
class EmployeeGsonSerializer implements JsonSerializer<Employee> {
    @Override
    public JsonElement serialize(Employee e, Type type, JsonSerializationContext jsc) {
        JsonObject jo = new JsonObject();
        jo.addProperty("id", e.getId());
        
        String fn = e.getFirstName();
        String ln = e.getLastName();
        jo.addProperty("firstName", fn);
        jo.addProperty("lastName", ln);
        jo.addProperty("displayName", fn + " " + ln);
        jo.addProperty("email", e.getEmail());
        jo.addProperty("leaf", Boolean.TRUE);

        return jo;
    }
}
